# -*- coding: UTF-8 -*-
from .models import UserLog

class SaveUserlog(object):
    def __init__(self,*args,**kwargs):
        super(SaveUserlog, self).__init__()
        self._abcd='test'

    def __call__(self,request,user=None,status=None,*args,**kwargs):
        request=request
        userlog=UserLog()
        meta=request.META
        userlog.method=request.method
        userlog.REMOTE_ADDR=meta['REMOTE_ADDR']
        userlog.HTTP_USER_AGENT=meta['HTTP_USER_AGENT']
        userlog.PATH_INFO=request.path_info
        userlog.user=user  or request.user
        userlog.namespace = request.path.split('/')[1] or '/'
        userlog.url_name=request.path.split('/')[-1] or '/'
        userlog.get_args=request.GET
        userlog.post_args=request.POST
        userlog.file_args=request.FILES
        userlog.status=status or 0
        userlog.save()







